package com.honeycomb.action.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import com.honeycomb.action.BaseAjaxAction;
import com.honeycomb.service.IUserService;
import com.honeycomb.utils.ErrorMsgConstants;
import com.honeycomb.utils.SystemConstants;
import com.honeycomb.vo.BaseVO;
import com.honeycomb.vo.ResultDto;
import com.honeycomb.vo.UserInfoVO;


/**
 * 
 * @author ZhongJiang
 * 
 * @function AJAX检查用户ID是否已经存在
 * 
 * @param userId 用户ID
 * 
 * @return json
 *
 */
public class AjaxCheckUserRegistEmailExistAction extends BaseAjaxAction {

	private IUserService iUserService;
	
	public IUserService getiUserService() {
		return iUserService;
	}
	public void setiUserService(IUserService iUserService) {
		this.iUserService = iUserService;
	}

	@Override
	protected JSONObject doRequest(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		logger.info("-----------------AjaxCheckUserRegistEmailExistAction---------------");
		JSONObject jo = new JSONObject();
		String userInfoId = (String)request.getParameter("userRegistEmail");
		
		UserInfoVO userInfoVO = null;
		ResultDto<BaseVO> resultDtoCheckEmailExist = null;
		try {
			userInfoVO = new UserInfoVO();
			userInfoVO.setUserId(userInfoId);
			resultDtoCheckEmailExist = this.iUserService.doCheckUserRegistEmailExist(userInfoVO);
			//resultVO.isSuccess表示已存在
			if(resultDtoCheckEmailExist.isSuccess()) {
				jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
				jo.put("msg", ErrorMsgConstants.ERR_USERID_IS_EXIST);
			}else {
				jo.put("result", SystemConstants.AJAX_SUCCESS);
			}
			return jo;
		} catch (Exception e) {
			e.printStackTrace();
			jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
			jo.put("msg", ErrorMsgConstants.ERR_SYSTEM);
			return jo;
		}
	}

	
}







